package com.yanlin.servicemap.client;

import com.mysql.cj.xdevapi.JsonArray;
import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.internalcommon.request.DicDistrict;
import com.yanlin.internalcommon.response.DicDirectionResponse;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

import static com.yanlin.internalcommon.constant.AmapConstant.*;

/**
 * <p>标题：DistrictClient</p>
 * <p>功能：</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-11 11:30</p>
 *
 * @author yanlin
 */
@Service
@Slf4j
public class DicDistrictClient {

    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    private RestTemplate restTemplate;

    public ResponseResult getDistrictData(String keywords) {
        // https://restapi.amap.com/v3/config/district?keywords=?&subdistrict=3&key=362dc4c59dbb673769e1c54a4317b190
        StringBuilder url = new StringBuilder(AMP_URI);
        url.append("/config/district");
        url.append("?keywords=").append(keywords);
        url.append("&subdistrict=3");
        url.append("&key=").append(amapKey);
        log.info("amap remote url = {}", url);
        ResponseEntity<String> result = restTemplate.getForEntity(url.toString(), String.class);
        return ResponseResult.success(result.getBody());
    }


}